package com.abc.intellihome.service;

import com.abc.intellihome.domain.User;
import com.abc.intellihome.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UserService {
    @Autowired
    public UserMapper userMapper;

    public int register(User user){
        int result =  userMapper.insert(user);
        return result;
    }

    public User loginUser(User user){
        User u;
        try {
            u=userMapper.selectById(user.username);
        }catch (RuntimeException e){
            return null;
        }
        return u;
    }

    public int changePassword(User user){
        int result = userMapper.updateById(user);

        return result;
    }

    public byte[] getUserAvatar(String username){
        return (byte[]) userMapper.getAvatarPic(username).get("imgBytes");
    }




}
